package o.gwtp.editor.client.gin;

import o.gwtp.editor.client.EditorPlaceManager;
import o.gwtp.editor.client.editor.EditorPresenter.EditorView;
import o.gwtp.editor.client.editor.EditorViewImpl;
import o.gwtp.editor.client.main.MainPresenter;
import o.gwtp.editor.client.main.MainView;
import o.gwtp.editor.client.navigation.NavigationTabPresenter;
import o.gwtp.editor.client.navigation.NavigationTabView;
import o.gwtp.editor.client.welcome.WelcomePresenter;
import o.gwtp.editor.client.welcome.WelcomeView;

import com.google.inject.Singleton;
import com.gwtplatform.mvp.client.DefaultEventBus;
import com.gwtplatform.mvp.client.DefaultProxyFailureHandler;
import com.gwtplatform.mvp.client.EventBus;
import com.gwtplatform.mvp.client.RootPresenter;
import com.gwtplatform.mvp.client.gin.AbstractPresenterModule;
import com.gwtplatform.mvp.client.proxy.ParameterTokenFormatter;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.ProxyFailureHandler;
import com.gwtplatform.mvp.client.proxy.TokenFormatter;

/**
 * @author Olivier Monaco
 * @author Christian Goudreau
 */
public class EditorModule extends AbstractPresenterModule {
  @Override
  protected void configure() {
    bind(EventBus.class).to(DefaultEventBus.class).in(Singleton.class);
    bind(PlaceManager.class).to(EditorPlaceManager.class).in(Singleton.class);
    bind(TokenFormatter.class).to(ParameterTokenFormatter.class).in(
        Singleton.class);
    bind(RootPresenter.class).asEagerSingleton();
    bind(ProxyFailureHandler.class).to(DefaultProxyFailureHandler.class).in(
        Singleton.class);

    bindPresenter(MainPresenter.class, MainPresenter.MyView.class,
        MainView.class, MainPresenter.MyProxy.class);
    bindPresenter(WelcomePresenter.class, WelcomePresenter.MyView.class,
        WelcomeView.class, WelcomePresenter.MyProxy.class);
    bindPresenterWidget(NavigationTabPresenter.class, NavigationTabPresenter.MyView.class,
        NavigationTabView.class);

    // Normal binding
    // bindPresenter(EditorPresenter.class, EditorView.class,
    // EditorViewImpl.class, EditorProxy.class);

    // Not singleton binding
    bind(EditorView.class).to(EditorViewImpl.class);
  }
}
